package data_access;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionFactory
{
	public static Connection getConnection()
	{
		try
		{
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            String dbConnectString = "jdbc:sqlserver://localhost;user=lab;password=lab;databaseName=lab"; 
            Connection con = DriverManager.getConnection (dbConnectString);
            
            return con;
		}
		catch (SQLException e)
		{
			System.out.println("Mensaje Error: " + e.getMessage());
			System.out.println("Stack Trace: " + e.getStackTrace());
			return null;
		}
		catch (Exception ex)
		{
			System.out.println("Mensaje Error: " + ex.getMessage());
			System.out.println("Stack Trace: " + ex.getStackTrace());
			return null;
		}
	}
	
	public static void closeConnection(Connection c)
	{
		try
		{
			c.close();
		} 
		catch (Exception e)
		{
			e.printStackTrace();
		}		
	}	
}